package ubiqweb.spring3.dao;

import java.util.List;

import ubiqweb.spring3.model.Attendees;
import ubiqweb.spring3.model.Training;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("attendeesDao")
public class AttendeesDaoImpl implements AttendeesDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	public List<Attendees> listMyTrainings(String userId) {																		
		//return (List<Attendees>) sessionFactory.getCurrentSession().createCriteria(Attendees.class).add(Restrictions.eq("userId", Integer.parseInt(userId))).list();	
		return (List<Attendees>) sessionFactory.getCurrentSession().createQuery("from Attendees where userId = '" + userId + "'").list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Attendees> listAttendees(String trainingId) {		
		return (List<Attendees>) sessionFactory.getCurrentSession().createCriteria(Attendees.class).add(Restrictions.eq("trainingId", Integer.parseInt(trainingId))).list();	
		}	

}